home *** CD-ROM | disk | FTP | other *** search
- Path: news.microsoft.com!news
- From: a-cnadc@microsoft.com (Dann Corbit)
- Newsgroups: comp.lang.c
- Subject: Re: Conversion between 80 and 64 bit doubles
- Date: 23 Feb 1996 18:49:10 GMT
- Organization: Microsoft Corporation
- Message-ID: <4gl276$1al@news.microsoft.com>
- References: <4gifto$aaa@news2.deltanet.com>
- NNTP-Posting-Host: 157.57.171.202
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4gifto$aaa@news2.deltanet.com>, fuz@deltanet.com says...
- >
- >
- >As part of a project I am working on, I have to convert between
- >an 80 bit double written on a PC to a 64 bit unix number. On
- >most platforms I have seen, this would not be all that hard,
- >since the one time it has come up, the 64 bit platform (Mac PPC) had a
- >conversion routine. This time, it will not be as kind, as the client
- >wants a more general answer. While I might be able to find a conversion
- >routine that will work on his AIX compiler, he has hinted darkly that he
- >will be moving to other compilers as well, and could I please write a
- >general converter?
- >
- >This is a fairly simple task in one sense - I know the numebrs in
- >question will be in range of 64 bit double, and that they will not be
- >NANs, so all I must do is convert the valid parts.
- >
- >Does anyone have a source for such a conversion routine, given that the
- >platform in question does not have an 80 bit type? The bit flipping for
- >PC-Unix is not a problem - that works already.
- >
- >(BTW, a URL for the official specs for 64 and 80 bit numbers would be
- >greatly appreciated. I have tried to find IEEE 754, but I have not
- >succeeded yet, which likely means that I am just searching for it in
- >entirely the wrong way.)
- >
- >Scott
- >--
- >Scott Ellsworth fuz@deltanet.com
- >"When a great many people are unable to find work, unemployment
- >results" - Calvin Coolidge, (Stanley Walker, City Editor, p. 131 (1934))
- >"The barbarian is thwarted at the moat." - Scott Adams
- I once wrote a general purpose floating point conversion routine.
- Create a structure that contains the following for each number type:
- 1. The number of significant bits "n"
- 2. The order of significance of the bits, from most significant to least (array).
- 3. The number of bits for the exponent.
- 4. The bias of the exponent.
- 5. The position of the sign.
- Now, to convert from one type to another,
- 1. Transfer the bits from most significant down to least.
- If there are too many bits, stop when the target is full.
- (you may want to perform special rounding here - banker's etc)
- If there are not enough bits, fill in the rest with 0 bits.
- 2. Convert the source exponent into an integer
- If the exponent is too large, trigger exception handling
- ( you might return MAX_<FLOATTYPE> or INF )
- If the exponent is too small, trigger exception handling
- ( you might return MIN_<FLOATTYPE> or 0 with TLOSS )
- 3. convert integer to target exponent format
- 4. Transfer exponent.
- 5. Transfer the sign.
- --
- The opinions expressed in this message are my own personal views
- and do not reflect the official views of Microsoft Corporation.
-
-